package epoch.game.core.distr.config;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 地图分布配置
 * @author will
 * @date 2016年6月23日 下午9:32:03
 */
public class MapDistrConfig {
	
	//地图组
	public int mapGroup;
	//节点 id
	public int nodeId;
	//节点分线起始
	public int lineFrom;
	//节点最大分线
	public int lineMax;
	
	//地图组分布 <mapGroup,config>
	public static Map<Integer, List<MapDistrConfig>> mapLocation = new HashMap<>();

	/**
	 * 判断地图组是否可能在该节点上
	 * @param group
	 * @param nodeId
	 * @return
	 */
	public static boolean isGroupOnNode(int group, int nodeId){
		List<MapDistrConfig> list = mapLocation.get(group);
		if (list != null && !list.isEmpty()) {
			for (MapDistrConfig mapConf : list) {
				if (mapConf.nodeId==nodeId) {
					return true;
				}
			}
		}else{
			return true;
		}
		return false;
	}
	
	/**
	 * 查找地图组分线应该分配到的节点id
	 * @param group
	 * @param nodeId
	 * @return
	 */
	public static int findLineNodeId(int group, int line){
		List<MapDistrConfig> list = mapLocation.get(group);
		if (list != null && !list.isEmpty()) {
			for (MapDistrConfig mapConf : list) {
				if (mapConf.lineFrom<=line && mapConf.lineMax>=line) {
					return mapConf.nodeId;
				}
			}
		}
		return 0;
	}
}
